package com.xkcun.crm.api;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xkcun.bi.feign.BiTestService;
import com.xkcun.crm.entity.Agree;
import com.xkcun.crm.param.AgreeListParam;
import com.xkcun.crm.service.AgreeService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 点赞表(Agree)表控制层
 *
 * @author yfz
 * @since 2021-08-06 13:49:32
 */
@Api(value = "", description = "")
@RestController
@RequestMapping("agree")
public class AgreeApi extends ApiController {
    /**
     * 服务对象
     */
    @Resource
    private AgreeService agreeService;

//    @Autowired
//    private BiTestService biTestService;


//    @ApiOperation(value = "测试远程调用", notes = "测试远程调用")
//    @PostMapping("/test")
//    public R test(@RequestParam List<Integer> ids) {
//        return success(biTestService.reports(ids));
//    }


    @ApiOperation(value = "分页查询", notes = "分页查询")
    @PostMapping("/page")
    public R page(AgreeListParam param) {
        Page<Agree> page = new Page(param.getPageIndex(), param.getPageSize());
        Agree agree = new Agree();
        BeanUtils.copyProperties(param, agree);
        return success(this.agreeService.page(page, new QueryWrapper<>(agree)));
    }

    @ApiOperation(value = "获取所有数据", notes = "获取所有数据")
    @PostMapping("/selectAll")
    public R selectAll() {
        return success(this.agreeService.list());
    }

    @ApiOperation(value = "详情查询", notes = "详情查询")
    @GetMapping("{id}")
    public R detail(@PathVariable Integer id) {
        return success(this.agreeService.getById(id));
    }

    @ApiOperation(value = "新增", notes = "新增")
    @PostMapping("/save")
    public R insert(@RequestBody Agree agree) {
        return success(this.agreeService.save(agree));
    }

    @ApiOperation(value = "修改", notes = "修改")
    @PostMapping("/update")
    public R update(@RequestBody Agree agree) {
        return success(this.agreeService.updateById(agree));
    }

    @ApiOperation(value = "删除", notes = "删除")
    @GetMapping("/del/{id}")
    public R delete(@PathVariable Integer id) {
        return success(this.agreeService.removeById(id));
    }
}